package com.tg.app.helper;

import androidx.annotation.NonNull;

import com.tange.core.backend.service.http.ClientObserver;
import com.tg.appcommon.android.TGLog;
import com.tg.data.bean.DeviceItem;
import com.tg.data.http.entity.AIGuardDataBean;
import com.tg.data.http.entity.EmptyBean;
import com.tg.data.http.entity.MessageTipDataBean;
import com.tg.network.socket.http.TGHttp;
import java.util.HashMap;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class GuardHelper {
    public static void updateAiGuardInfo(int sw, String uuid, int interval, String start, String end, @NonNull final GuardHelper.GuardListener<EmptyBean> listener){
        HashMap<String, Object> map = new HashMap<>();
        map.put("switch", sw);
        map.put("uuid", uuid);
        map.put("interval", interval);
        map.put("start", start);
        map.put("end", end);

        TGHttp.getInstance().updateAiGuardInfo(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ClientObserver<EmptyBean>() {
                    @Override
                    protected void onSuccess(final EmptyBean content) {
                        listener.onSuccess(content);
                    }

                    @Override
                    protected void onResponseError(int errorCode, String errorInfo) {
                        listener.onError(errorCode, errorInfo);

                    }

                    @Override
                    protected void onOtherError(String error) {
                        TGLog.d("error = " + error);
                    }
                });
    }

    public static void getAiGuardInfo(DeviceItem deviceItem, @NonNull final GuardHelper.GuardListener<AIGuardDataBean> listener){
        String uuid =  deviceItem == null? "0" : deviceItem.uuid;
        HashMap<String, String> map = new HashMap<>();
        map.put("uuid", uuid);

        TGHttp.getInstance().getAiGuardInfo(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ClientObserver<AIGuardDataBean>() {
                    @Override
                    protected void onSuccess(final AIGuardDataBean content) {
                        listener.onSuccess(content);
                    }

                    @Override
                    protected void onResponseError(int errorCode, String errorInfo) {
                        TGLog.d("errorInfo = " + errorInfo);
                    }

                    @Override
                    protected void onOtherError(String error) {
                        TGLog.d("error = " + error);
                    }
                });
    }


    public static void getAlarmSetupTip(DeviceItem deviceItem, @NonNull final GuardListener<MessageTipDataBean> listener){
        String uuid =  deviceItem == null? "0" : deviceItem.uuid;
        HashMap<String, String> map = new HashMap<>();
        map.put("uuid", uuid);
        map.put("tag", "guard");
        map.put("from", "guard");
        TGHttp.getInstance().getAlarmSetupTip(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ClientObserver<MessageTipDataBean>() {
                    @Override
                    protected void onSuccess(final MessageTipDataBean content) {
                        listener.onSuccess(content);
                    }

                    @Override
                    protected void onResponseError(int errorCode, String errorInfo) {
                        listener.onError(errorCode, errorInfo);
                    }

                    @Override
                    protected void onOtherError(String error) {
                        TGLog.d("error = " + error);
                    }
                });



    }

    public interface GuardListener<T> {
        void onSuccess(T content);
        void onError(int errorCode, String errorInfo);
    }
}
